﻿using Autofac.Core;
using DFGK.IService;
using DFGK.Service;
using DFGK_WMS.Common;
using Microsoft.AspNetCore.Mvc;

namespace DFGK_WMS.WebAPI.Controllers.PC.入库管理
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    [ApiExplorerSettings(GroupName = "PC")]
    public class DefectiveProductsController : BaseController
    {
        private readonly IInventoryService _inventoryService;
        public DefectiveProductsController(IWebHostEnvironment environment, IInventoryService _inventoryService) : base(environment)
        {
            this._inventoryService = _inventoryService;
        }

        /// <summary>
        /// 不良品查询查全部
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public IActionResult GetDefectiveProducts(int pageIndex, int pageSize)
        {
            var list = _inventoryService.GetDefectiveProducts(pageIndex, pageSize,  out int totalCount);
            return Ok(BaseResult.Result(list, "查询成功", "200", totalCount));
        }

        /// <summary>
        /// 导出不良品
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public IActionResult DowLoadExcel()
        {
            var list = _inventoryService.GetDefectiveProducts();
            if (list != null)
                return InvDown(list);
            else
                return Ok();
        }
    }
}
